package com.atguigu.gmall.product.api;

import com.alibaba.fastjson.JSONObject;
import com.atguigu.gmall.common.result.Result;
import com.atguigu.gmall.model.product.*;
import com.atguigu.gmall.product.service.ApiSkuInfoService;
import com.atguigu.gmall.product.service.BaseSaleAttrService;
import com.atguigu.gmall.product.service.SpuPosterService;
import com.atguigu.gmall.product.service.SpuSaleAttrService;
import org.simpleframework.xml.Path;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.math.BigDecimal;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/api/product")
public class ProductApiController {

    @Autowired
    private ApiSkuInfoService apiSkuInfoService;

    @Autowired
    private SpuSaleAttrService spuSaleAttrService;

    @Autowired
    private SpuPosterService spuPosterService;


    /**
     * a.	获取skuInfo 基本信息+ 商品的图片列表数据！
     * 								skuInfo + skuImageList
     */
    @GetMapping("inner/getSkuInfo/{skuId}")
    public SkuInfo getAttrValueList(@PathVariable Long skuId){

        SkuInfo skuInfo = apiSkuInfoService.getAttrValueList(skuId);
        System.out.println("skuInfo = " + skuInfo);

        // 返回数据
        return skuInfo;
    }

    // 根据skuid获取最新价格数据
    @GetMapping("inner/getSkuPrice/{skuId}")
    public BigDecimal getSkuPrice(@PathVariable Long skuId){
        return apiSkuInfoService.getSkuPrice(skuId);
    }

    // 获取商品分类
    // /api/product/inner/getCategoryView/{category3Id}
    @GetMapping("inner/getCategoryView/{category3Id}")
    public BaseCategoryView getCategoryView(@PathVariable Long category3Id){
        return apiSkuInfoService.getCategoryView(category3Id);
    }

    // 获取销售属性 + 销售属性值
    //inner/getSpuSaleAttrListCheckBySku/{skuId}/{spuId}
    @GetMapping("inner/getSpuSaleAttrListCheckBySku/{skuId}/{spuId}")
    public List<SpuSaleAttr> getSpuSaleAttrListCheckBySku(@PathVariable Long skuId,@PathVariable Long spuId){

        List<SpuSaleAttr> spuSaleAttrList = spuSaleAttrService.getSpuSaleAttrListCheckBySku(skuId,spuId);

        return spuSaleAttrList;

    }

     // 实现商品的切换功能
     // @GetMapping("inner/getSkuValueIdsMap/{spuId}")
    @GetMapping("inner/getSkuValueIdsMap/{spuId}")
    public Map<Object, Object> getSkuValueIdsMap(@PathVariable Long spuId){
        return apiSkuInfoService.getSkuValueIdsMap(spuId);
    }

    // 获取海报信息
    // @GetMapping("inner/findSpuPosterBySpuId/{spuId}")
    @GetMapping("inner/findSpuPosterBySpuId/{spuId}")
    public List<SpuPoster> findSpuPosterBySpuId(@PathVariable Long spuId){
        return spuPosterService.findSpuPosterBySpuId(spuId);
    }

    // sku对应的平台属性，也就是规格
    // @GetMapping("inner/getAttrList/{skuId}")
    @GetMapping("inner/getAttrList/{skuId}")
    public List<BaseAttrInfo> getAttrList(@PathVariable Long skuId){
        return apiSkuInfoService.getAttrList(skuId);
    }

    /**
     * 获取全部分类信息
     * @return
     */
    @GetMapping("getBaseCategoryList")
    public Result getBaseCategoryList(){
        List<JSONObject> list = apiSkuInfoService.getBaseCategoryList();
        return Result.ok(list);
    }

    /**
     * 查询品牌信息
     */
    @GetMapping("getBaseTradeMark/{tmId}")
    public BaseTrademark getBaseTradeMark(@PathVariable Long tmId){
        BaseTrademark baseTrademark = apiSkuInfoService.getBaseTradeMark(tmId);
        return baseTrademark;
    }


}
